home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Camelot / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].zip / Camelot 043 (1989-06)(Swedish User Group of Amiga)(SE)(PD)[WB].adf / printfx / offswitch.a < prev    next >
Text File  |  1989-06-08  |  5KB  |  152 lines

  1. *  Here three routines are defined: MakeOffswitch, TestOffSwitch and
  2. *  RemOffSwitch. They exist to replace the keyboard abort ^C by a kind of
  3. *  push button, labeled with the programname. So programs running in the
  4. *  background are easy reachable and you can/must use your own closing
  5. *  down. Must perhaps, because you MUST call RemOffSwitch before
  6. *  termination, otherwise the window exits forever and every push on the
  7. *  offswitch withdraws 56 bytes of the pool.
  8. *  MakeOffSwitch() may be used to make one window. Subsequent calls just
  9. *  return the (already existing) window pointer.
  10. *  
  11.  
  12. *    nolist        
  13.     ifnd    ifiles
  14. ifiles    set    1
  15.     include    "exec/types.i"
  16.     include    "intuition/intuition.i"
  17.     endc
  18. *    list
  19.  
  20. LEFT    equ    640/2            Middle of the screen
  21. TOP    equ    0
  22. WIDTH    equ    640/2            Half a screen
  23. HEIGHT    equ    10            Normal dragbar height
  24.  
  25.     xdef    _MakeOffSwitch,MakeOffSwitch
  26.     xdef    _TestOffSwitch,TestOffSwitch
  27.     xdef    _RemOffSwitch,RemOffSwitch
  28.  
  29.     xref    _LVOOpenLibrary
  30.     xref    _LVOOpenWindow
  31.     xref    _LVOGetMsg
  32.     xref    _LVOReplyMsg
  33.     xref    _LVOCloseWindow
  34.     xref    _LVOCloseLibrary
  35.  
  36. _AbsExecBase    equ    4
  37.  
  38.     csect    OffSwitch,0,0,1,2
  39.  
  40. *
  41. *  From C:
  42. *  if (MakeOffSwitch(Title)!=NULL)  /* then there is a window! */
  43. *  else  /* there is no window, but further no problem */
  44. *  Title is a pointer to a '\0' terminated string.
  45. *  MakeOffSwitch returns a pointer to the Window structure. Ignore it
  46. *  or use it, perhaps to change the window. However you may not remove it.
  47. *
  48. *  Intuition is opened, but when the OpenWindow fails, intuition is closed
  49. *  immediate. So if this routine returns NULL, it is not necesary to call
  50. *  RemOffSwitch, although this would cause no problem.
  51. *
  52.  
  53. _MakeOffSwitch:
  54.     move.l    4(a7),a0
  55. MakeOffSwitch:
  56.     move.l    a0,Title(a4)        Text in bar into NewWindow-$
  57.     move.l    a6,-(a7)        Keep callers a6
  58.     move.l    Wind(a4),d0        See if there is already a window
  59.     bne.s    QMOS            Yes, return its pointer
  60.     move.l    IBase(a4),d0        See if Intuition is already open
  61.     bne.s    GotI
  62.     move.l    _AbsExecBase,a6        Get Exec-function pointer
  63.     lea.l    IntuName(pc),a1        "intuition.library"
  64.     moveq.l    #0,d0            Any version is OK
  65.     jsr    _LVOOpenLibrary(a6)    Get Intuition library
  66.     move.l    d0,IBase(a4)        Keep for later
  67.     beq.s    QMOS            No intu; no window
  68. GotI    move.l    d0,a6            Get intu pointer
  69.     lea.l    NewWind(a4),a0        Get NewWindow structure
  70.     jsr    _LVOOpenWindow(a6)    Open a window
  71.     move.l    d0,Wind(a4)        Keep pointer, so we can close it
  72.     beq.s    CloseI            No window, Intu of no use
  73. QMOS    move.l    (a7)+,a6        Restore callers a6
  74.     rts
  75.  
  76. *
  77. *  From C:
  78. *  if (TestOffSwitch()!=0)  /* then close gadget was stirred */
  79. *  else  /* close gadged was passed */
  80. *  This may be done more then once, the message is just passed.
  81. *
  82. *  Even if there is no window,  it is allowed to call this routine. 
  83. *  Then it just returns zero.
  84. *
  85.  
  86. _TestOffSwitch:
  87. TestOffSwitch:
  88.     move.l    a6,-(a7)        Keep callers a6
  89.     move.l    _AbsExecBase,a6        Get Exec-function pointer
  90.     move.l    Wind(a4),d0        Get Window-$
  91.     beq.s    QTOS            If none quit
  92.     move.l    d0,a1            We need a member so use a-reg
  93.     move.l    wd_UserPort(a1),a0    Get connection to our window
  94.     jsr    _LVOGetMsg(a6)        See if ther's a message
  95.     tst.l    d0            non-zero is truly a message
  96.     beq.s    QTOS            zero means no message
  97.     move.l    d0,a1            a1 is used to reply
  98.     move.l    im_Class(a1),-(a7)    Keep interesting part of mess
  99.     jsr    _LVOReplyMsg(a6)    Return message ownership
  100.     move.l    (a7)+,d0        Get interesting part
  101.     cmp.l    #CLOSEWINDOW,d0        We look only for closewindow
  102.     bne.s    QZero            If not we return zero
  103. QTOS    move.l    (a7)+,a6        If true we return CLOSEWINDOW
  104.     rts
  105.  
  106. *
  107. *  From C:
  108. *  RemOffSwitch();   /* removes the window */
  109. *
  110. *  Even if there was no window, it is allowed to call this routine.
  111. *
  112.     
  113. _RemOffSwitch:
  114. RemOffSwitch:
  115.     move.l    a6,-(a7)        Save callers a6
  116.     move.l    IBase(a4),d0        Get key to intuition
  117.     beq.s    QROS            If none asume ready
  118.     move.l    d0,a6            a6 is used to enter intuition
  119.     move.l    Wind(a4),d0        Get window structure
  120.     beq.s    CloseI            If none close intuition
  121.     move.l    d0,a0            A0 is parameter port
  122.     jsr    _LVOCloseWindow(a6)    Close our window
  123.     clr.l    Wind(a4)        Aint that nice?
  124. CloseI    move.l    a6,a1            A1 is parameter port
  125.     move.l    _AbsExecBase,a6        Get key to Exec
  126.     jsr    _LVOCloseLibrary(a6)    Close intuition
  127.     clr.l    IBase(a4)        There is NO intuition anymore..
  128. QZero    moveq.l    #0,d0            This routine always returns 0
  129. QROS    move.l    (a7)+,a6        Callers a6
  130.     rts
  131.     
  132. IntuName dc.b 'intuition.library',0
  133.  
  134.     csect    __MERGED,1,,2,2
  135.  
  136. ***  The NewWindow structure
  137.  
  138. NewWind dc.w    LEFT,TOP,WIDTH,HEIGHT
  139.     dc.b    -1,-1
  140.     dc.l    CLOSEWINDOW
  141.     dc.l    WINDOWDRAG!WINDOWCLOSE!WINDOWDEPTH
  142.     dc.l    0,0
  143. Title    dc.l    0
  144.     dc.l    0,0
  145.     dc.w    0,0,0,0
  146.     dc.w    WBENCHSCREEN
  147.     
  148. Wind    ds.l    1
  149. IBase    ds.l    1
  150.  
  151.     end
  152.